package com.ymatou.iapi.userservice.testcase;

import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.QueryTradingPwdOpercordsBean;
import com.ymatou.iapi.userservice.parameter.UpdateTradingPwdBean;
import com.ymatou.iapi.userservice.parameter.enums.LoginNameEnum;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.CreateUserCall;
import com.ymatou.iapi.userservice.service.QueryTradingPwdOpercordsCall;
import com.ymatou.iapi.userservice.service.UpdateTradingPwdCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*查询交易密码最后修改时间Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryTradingPwdOpercords{
	private static QueryTradingPwdOpercordsBean querytradingpwdopercordsBean;
	private static QueryTradingPwdOpercordsCall querytradingpwdopercordsCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询交易密码最后修改时间Test");
	}

	@Before
	public void caseUp() {
		querytradingpwdopercordsBean=new QueryTradingPwdOpercordsBean();
		querytradingpwdopercordsCall=new QueryTradingPwdOpercordsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querytradingpwdopercordsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryTradingPwdOpercords_001() {
		Logger.start(true,"查询交易密码最后修改时间,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			
			UpdateTradingPwdBean updatetradingpwdBean = new UpdateTradingPwdBean();
			UpdateTradingPwdCall updatetradingpwdCall = new UpdateTradingPwdCall();
			
			//设置交易密码
			updatetradingpwdBean.setUserId(uid);
			updatetradingpwdBean.setOldPassword(null);
			updatetradingpwdBean.setNewPassword("abc123");
			// ModifyTradingPassword 或 ModifyLoginPassword
			updatetradingpwdBean.setPasActionType("ModifyTradingPassword");
			updatetradingpwdBean.setLoginMobile(cur.getMobile());
			// ByUserId 或 ByMobile
			updatetradingpwdBean.setAType("ByUserId");
			updatetradingpwdCall.setData(updatetradingpwdBean);
			updatetradingpwdCall.callService();
			
			querytradingpwdopercordsBean.setUserId(uid);
			querytradingpwdopercordsBean.setPType(2);
			querytradingpwdopercordsCall.setData(querytradingpwdopercordsBean);
			querytradingpwdopercordsCall.callService();	
			
			Logger.verifyEquals("true", querytradingpwdopercordsCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", querytradingpwdopercordsCall.getString("ResponseCode"), "验证ResponseCode");
			
			//验证Userinfo的LastUpdateTime
			JUserWapper ju = new JUserWapper();
			List<Userinfo> lui = ju.selectUserinfoByUid(uid);
			Userinfo ui = lui.get(0);
			//Logger.comment("11111111111111111111111"+YMTDateUtil.getFormatDateString(ui.getLastUpdateTime()).toString());
			String time = YMTDateUtil.getFormatTime(ui.getLastUpdateTime(), "yyyy-MM-dd HH:mm:ss");
			Logger.verifyNotNull(querytradingpwdopercordsCall.getString("Result"), "验证Result");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryTradingPwdOpercords_002() {
		Logger.start(true,"uid不存在查询交易密码最后修改时间,失败");
		try {			
			
			querytradingpwdopercordsBean.setUserId(0000);
			querytradingpwdopercordsBean.setPType(2);
			querytradingpwdopercordsCall.setData(querytradingpwdopercordsBean);
			querytradingpwdopercordsCall.callService();	
			
			Logger.verifyEquals("true", querytradingpwdopercordsCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100001", querytradingpwdopercordsCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("未找到密码更新记录", querytradingpwdopercordsCall.getString("LastErrorMessage"), "验证LastErrorMessage");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryTradingPwdOpercords_003() {
		Logger.start(true,"交易密码不存在,默认最小时间成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);	
		
			querytradingpwdopercordsBean.setUserId(uid);
			querytradingpwdopercordsBean.setPType(2);
			querytradingpwdopercordsCall.setData(querytradingpwdopercordsBean);
			querytradingpwdopercordsCall.callService();	
			
			Logger.verifyEquals("true", querytradingpwdopercordsCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100001", querytradingpwdopercordsCall.getString("ResponseCode"), "验证ResponseCode");
			//Logger.verifyIsContains("该用户交易密码为null", querytradingpwdopercordsCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}